<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  
  <title>Android之内存管理初窥 | 赵天恩博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Android之内存管理初窥0.前奏相信每个从事android开发的人员来说，都或多或少的遇到过OOM情况的，因此对于每个coder来说能够避免或者防范OOM出现确实是一门必不可少的能力。因此，接下来咱们就谈谈android平台下内存的管理之道。
1.概念回顾内存泄漏：指对象在内存heap堆中分配的空间，当不再适用或者没有引用指向的情况下，仍不能被GC正常回收的情况。在android平台下多数出现">
<meta property="og:type" content="article">
<meta property="og:title" content="Android之内存管理初窥">
<meta property="og:url" content="http://zhaotianen.github.io/2016/04/23/android/Android之内存管理初窥/index.html">
<meta property="og:site_name" content="赵天恩博客">
<meta property="og:description" content="Android之内存管理初窥0.前奏相信每个从事android开发的人员来说，都或多或少的遇到过OOM情况的，因此对于每个coder来说能够避免或者防范OOM出现确实是一门必不可少的能力。因此，接下来咱们就谈谈android平台下内存的管理之道。
1.概念回顾内存泄漏：指对象在内存heap堆中分配的空间，当不再适用或者没有引用指向的情况下，仍不能被GC正常回收的情况。在android平台下多数出现">
<meta property="og:image" content="http://zhaotianen.github.io/2016/04/23/android/Android之内存管理初窥/1461412741168.png">
<meta property="og:updated_time" content="2017-09-01T14:25:12.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android之内存管理初窥">
<meta name="twitter:description" content="Android之内存管理初窥0.前奏相信每个从事android开发的人员来说，都或多或少的遇到过OOM情况的，因此对于每个coder来说能够避免或者防范OOM出现确实是一门必不可少的能力。因此，接下来咱们就谈谈android平台下内存的管理之道。
1.概念回顾内存泄漏：指对象在内存heap堆中分配的空间，当不再适用或者没有引用指向的情况下，仍不能被GC正常回收的情况。在android平台下多数出现">
<meta name="twitter:image" content="http://zhaotianen.github.io/2016/04/23/android/Android之内存管理初窥/1461412741168.png">
  
    <link rel="alternative" href="/atom.xml" title="赵天恩博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
      <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  
  
  
      <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
      <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">
  
  <link rel="stylesheet" href="/css/style.css">
  
  <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  
  
    <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  
  <script src="//cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
  <script>
      var yiliaConfig = {
          fancybox: true,
          animate: true,
          isHome: false,
          isPost: true,
          isArchive: false,
          isTag: false,
          isCategory: false,
          open_in_new: true,
      }
  </script>

  
      <script>
          yiliaConfig.rootUrl = "/";
      </script>
  

  

  
</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">赵天恩</a></h1>
        </hgroup>

        
        <p class="header-subtitle">赵天恩博客</p>
        
                


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                            <li><a href="/2017/09/01/about/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <li id="Email"><a class="Email" target="_blank" href="mailto:ztelovecly@gmail.com" title="Email"></a></li>
                            
                                <li id="GitHub"><a class="GitHub" target="_blank" href="https://github.com/zhaotianen" title="GitHub"></a></li>
                            
                                <li id="QQ"><a class="QQ" target="_blank" href="tencent://message/?uin=909442787&Site=&menu=yes" title="QQ"></a></li>
                            
                                <li id="微信"><a class="微信" target="_blank" href="/zte_cly" title="微信"></a></li>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <a href="/tags/Android/" style="font-size: 16.67px;">Android</a> <a href="/tags/Android系统源代码情景分析/" style="font-size: 10px;">Android系统源代码情景分析</a> <a href="/tags/Git/" style="font-size: 13.33px;">Git</a> <a href="/tags/Github/" style="font-size: 13.33px;">Github</a> <a href="/tags/Hadoop权威指南/" style="font-size: 10px;">Hadoop权威指南</a> <a href="/tags/HashMap/" style="font-size: 10px;">HashMap</a> <a href="/tags/Hexo/" style="font-size: 13.33px;">Hexo</a> <a href="/tags/IntelliJ-IDEA/" style="font-size: 13.33px;">IntelliJ IDEA</a> <a href="/tags/Java并发编程-核心方法与框架/" style="font-size: 10px;">Java并发编程-核心方法与框架</a> <a href="/tags/Java核心技术-卷1/" style="font-size: 10px;">Java核心技术-卷1</a> <a href="/tags/Java核心技术-卷2/" style="font-size: 10px;">Java核心技术-卷2</a> <a href="/tags/Linux私房菜-基础学习篇/" style="font-size: 10px;">Linux私房菜-基础学习篇</a> <a href="/tags/Node-js/" style="font-size: 13.33px;">Node.js</a> <a href="/tags/RBAC/" style="font-size: 10px;">RBAC</a> <a href="/tags/android/" style="font-size: 16.67px;">android</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/jvm/" style="font-size: 10px;">jvm</a> <a href="/tags/linux/" style="font-size: 10px;">linux</a> <a href="/tags/mac/" style="font-size: 10px;">mac</a> <a href="/tags/maven/" style="font-size: 10px;">maven</a> <a href="/tags/mysql/" style="font-size: 10px;">mysql</a> <a href="/tags/springBoot/" style="font-size: 10px;">springBoot</a> <a href="/tags/关于我/" style="font-size: 10px;">关于我</a> <a href="/tags/大数据/" style="font-size: 13.33px;">大数据</a> <a href="/tags/大数据之路/" style="font-size: 10px;">大数据之路</a> <a href="/tags/实践Java虚拟机-JVM故障诊断与性能优化/" style="font-size: 10px;">实践Java虚拟机-JVM故障诊断与性能优化</a> <a href="/tags/架构/" style="font-size: 10px;">架构</a> <a href="/tags/架构即未来/" style="font-size: 10px;">架构即未来</a> <a href="/tags/深入实践SpringBoot/" style="font-size: 10px;">深入实践SpringBoot</a> <a href="/tags/深入解析Android5-0系统/" style="font-size: 10px;">深入解析Android5.0系统</a> <a href="/tags/第一行代码/" style="font-size: 10px;">第一行代码</a> <a href="/tags/轻量级JavaEE企业应用实践/" style="font-size: 10px;">轻量级JavaEE企业应用实践</a> <a href="/tags/重构/" style="font-size: 10px;">重构</a> <a href="/tags/高性能MySql/" style="font-size: 10px;">高性能MySql</a>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于Java</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">赵天恩</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">赵天恩</a></h1>
            </hgroup>
            
            <p class="header-subtitle">赵天恩博客</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                    <li><a href="/2017/09/01/about/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <li id="Email"><a class="Email" target="_blank" href="mailto:ztelovecly@gmail.com" title="Email"></a></li>
                            
                                <li id="GitHub"><a class="GitHub" target="_blank" href="https://github.com/zhaotianen" title="GitHub"></a></li>
                            
                                <li id="QQ"><a class="QQ" target="_blank" href="tencent://message/?uin=909442787&Site=&menu=yes" title="QQ"></a></li>
                            
                                <li id="微信"><a class="微信" target="_blank" href="/zte_cly" title="微信"></a></li>
                            
                        </ul>
            </nav>
        </header>                
    </div>
</nav>
      <div class="body-wrap"><article id="post-android/Android之内存管理初窥" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/04/23/android/Android之内存管理初窥/" class="article-date">
      <time datetime="2016-04-23T12:16:30.000Z" itemprop="datePublished">2016-04-23</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Android之内存管理初窥
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/categories/Android/">Android</a>
    </div>


        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Android/">Android</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h1 id="Android之内存管理初窥"><a href="#Android之内存管理初窥" class="headerlink" title="Android之内存管理初窥"></a>Android之内存管理初窥</h1><h2 id="0-前奏"><a href="#0-前奏" class="headerlink" title="0.前奏"></a>0.前奏</h2><p>相信每个从事android开发的人员来说，都或多或少的遇到过OOM情况的，因此对于每个coder来说能够避免或者防范OOM出现确实是一门必不可少的能力。因此，接下来咱们就谈谈android平台下内存的管理之道。</p>
<h2 id="1-概念回顾"><a href="#1-概念回顾" class="headerlink" title="1.概念回顾"></a>1.概念回顾</h2><p>内存泄漏：<br>指对象在内存heap堆中分配的空间，当不再适用或者没有引用指向的情况下，仍不能被GC正常回收的情况。在android平台下多数出现在代码的不合理下，通常大量的内存泄漏会造成 OOM的出现。</p>
<p>OOM：<br>即OutOfMemoery，中文也就是内存溢出。内存溢出是指app向系统申请的超过内存最大阀值的内存请求，系统不会再分配多余的空间出来，就会造成OOM ERROR，在android平台下大多数出现在图片处理不当的时候。</p>
<h2 id="2-原因分析"><a href="#2-原因分析" class="headerlink" title="2.原因分析"></a>2.原因分析</h2><ul>
<li><strong>static</strong> ：<br>static是个好东西，声明赋值然后就可以调用，但是伴随而来的就是性能问题。由于static声明变量的生命周期和app的生命周期一样的，有点类似与application。如果大量使用，势必占剧内存空间且不释放，积少成多就会造成内存不断开销，直至挂掉。static的合理使用一般用来修饰基本数据类型或者轻量级对象，尽量避免修复集合或者大对象，常用作修饰全局配置项、工具类方法、内部类。</li>
<li><strong>无关引用</strong>：<br>在android中很多情况下需要用到传递引用，但是无法确保引用传递出去后能否及时的回收。例如context泄露，但是很多情况下activity结束后，但是由于仍被其他的对象指向导致一直迟迟不能回收，就会导致内存泄漏。</li>
<li><p><strong>handler</strong>：<br>在做一步操作的时候，相信很多人都会使用handler+thread方式的。handler运行在UI线程，不断处理来自消息队列的消息，如果handler还有消息需要处理，但是activity页面已经结束了，这个时候activity引用其实不会被回收，就会造成内存泄漏。解决方案一是在activity的onDestrory方法中调用handler.removeCallbackAndMessage(null)来取消所有的消息的处理，包括待处理的消息；二是声明handler的内部类为static。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MainActivity</span> <span class="keyword">extends</span> <span class="title">Activity</span> </span>&#123;</span><br><span class="line"> <span class="comment">//	  目前现状开始</span></span><br><span class="line"> <span class="comment">//   private Handler mHandler = new Handler() &#123;</span></span><br><span class="line"> <span class="comment">//       @Override</span></span><br><span class="line"> <span class="comment">//       public void handleMessage(Message msg) &#123;</span></span><br><span class="line"> <span class="comment">//       &#125;</span></span><br><span class="line"> <span class="comment">//   &#125;;</span></span><br><span class="line"> <span class="comment">//   目前现状结束</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//   修改后开始</span></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">MyHandler</span> <span class="keyword">extends</span> <span class="title">Handler</span> </span>&#123;</span><br><span class="line">        <span class="keyword">private</span> <span class="keyword">final</span> WeakReference&lt;MainActivity&gt; mActivity;</span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="title">MyHandler</span><span class="params">(MainActivity activity)</span></span>&#123;</span><br><span class="line">            mActivity = <span class="keyword">new</span> WeakReference&lt;MainActivity&gt;(activity);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">handleMessage</span><span class="params">(Message msg)</span> </span>&#123;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> <span class="comment">//   修改后结束</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_main);</span><br><span class="line">        loadData();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">loadData</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">// ...request</span></span><br><span class="line">        Message message = Message.obtain();</span><br><span class="line">        mHandler.sendMessage(message);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>bitmap</strong>：<br>bitmap在android的oom中占据不可替代的角色，所以操作bitmap的时候需要十分的注意了。由于Dalivk并不会主动的去回收，需要开发者在bitmap不被使用的 时候recyle掉，同时对bitmap操作的时候，没有特别需求的时候，最好能做到压缩像素，最后建议大家加载图片的时候，能够使用软引用或者弱引用并进行本地缓存，推荐使用android-universal-imageloader。</p>
</li>
<li><strong>cursor</strong>：<br>操作数据库的时，会返回一个cursor，当查询完毕后，需要及时关闭，这样就可以把查询到结果集及时给回收掉。</li>
<li><strong>页面背景和图片加载</strong>：<br>在布局或者代码中设置背景和图片的时候，如果是纯色的话，尽量使用color，如果是规则图形，尽量使用shape画图，如果稍微复杂点，可以使用9patch图。</li>
<li><strong>ListView和GridView的item缓存</strong>：<br>在现实列表的时候，页面绘制是个很耗时的操作，所以重用view就显得尤为重要，否则会出现滑动很卡的现象。</li>
<li><strong>BroadCastRecevier和Service</strong>：<br>绑定广播和服务的时候，一定要在不需要的时候给解绑。</li>
<li><strong>I/0流</strong>：<br>I/O操作完毕的时候，读写结束一定要关闭</li>
<li><strong>线程</strong>：<br>线程不再需要继续执行的时候要记得及时关闭，开启线程数量也不要过多，一般和自己机器内核数一样最好，推荐开启线程的时候，使用线程池。</li>
<li><strong>String/StringBuffer</strong>：<br>当有较多的字符创需要拼接的时候，推荐使用StringBuffer。</li>
<li><strong>单例</strong>：<br>将context对象保存在单例模式中，instance对象本身持有一个context对象的引用，活动即使被销毁也不能被回收，因此静态变量一直持有它的引用。<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AppManager</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> AppManager instance;</span><br><span class="line">    <span class="keyword">private</span> Context context;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="title">AppManager</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">	    <span class="comment">//修改前</span></span><br><span class="line">        <span class="comment">//this.context = context;</span></span><br><span class="line">        <span class="comment">//修改后</span></span><br><span class="line">        <span class="keyword">this</span>.context = context.getApplicationContext();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> AppManager <span class="title">getInstance</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (instance != <span class="keyword">null</span>) &#123;</span><br><span class="line">            instance = <span class="keyword">new</span> AppManager(context);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> instance;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="3-解决工具"><a href="#3-解决工具" class="headerlink" title="3.解决工具"></a>3.解决工具</h2><p>Memory Monitor 内存监视器<br><img src="/2016/04/23/android/Android之内存管理初窥/1461412741168.png" alt="Alt text"></p>
<h2 id="4-终极建议"><a href="#4-终极建议" class="headerlink" title="4.终极建议"></a>4.终极建议</h2><ul>
<li>尽量不要让静态变量引用Activity</li>
<li>使用WeakReference弱引用，会保证GC时会被回收</li>
<li>使用静态内部类来代替内部类，静态内部类不持有外部类的引用</li>
<li>静态内部类使用弱引用来引用外部类</li>
<li>在声明周期结束的时候释放资源</li>
</ul>

      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/2016/04/23/android/Android之内存管理初窥/">Android之内存管理初窥</a></p>
        <p><span>文章作者:</span><a href="/" title="回到主页">赵天恩</a></p>
        <p><span>发布时间:</span>2016-04-23, 20:16:30</p>
        <p><span>最后更新:</span>2017-09-01, 22:25:12</p>
        <p>
            <span>原始链接:</span><a class="post-url" href="/2016/04/23/android/Android之内存管理初窥/" title="Android之内存管理初窥">http://zhaotianen.github.io/2016/04/23/android/Android之内存管理初窥/</a>
            <span class="copy-path" data-clipboard-text="原文: http://zhaotianen.github.io/2016/04/23/android/Android之内存管理初窥/　　作者: 赵天恩" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script src="/js/clipboard.min.js"></script>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" title="CC BY-NC-SA 4.0 International" target = "_blank">"署名-非商用-相同方式共享 4.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>



    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/2017/09/01/maven/mac_maven配置/">
                    mac上maven配置
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2016/04/23/android/android-checklist/">
                    Android开发过程中注意项(CheckList)
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Android之内存管理初窥"><span class="toc-number">1.</span> <span class="toc-text">Android之内存管理初窥</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#0-前奏"><span class="toc-number">1.1.</span> <span class="toc-text">0.前奏</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-概念回顾"><span class="toc-number">1.2.</span> <span class="toc-text">1.概念回顾</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-原因分析"><span class="toc-number">1.3.</span> <span class="toc-text">2.原因分析</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-解决工具"><span class="toc-number">1.4.</span> <span class="toc-text">3.解决工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-终极建议"><span class="toc-number">1.5.</span> <span class="toc-text">4.终极建议</span></a></li></ol></li></ol>
</div>
<style>
    .left-col .switch-btn {
        display: none;
    }
    .left-col .switch-area {
        display: none;
    }
</style>

<input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">
<script>
    var valueHide = "隐藏目录";
    var valueShow = "显示目录";

    if ($(".left-col").is(":hidden")) {
        $("#tocButton").attr("value", valueShow);
    }

    $("#tocButton").click(function() {
        if ($("#toc").is(":hidden")) {
            $("#tocButton").attr("value", valueHide);
            $("#toc").slideDown(320);
            $(".switch-btn, .switch-area").fadeOut(300);
        }
        else {
            $("#tocButton").attr("value", valueShow);
            $("#toc").slideUp(350);
            $(".switch-btn, .switch-area").fadeIn(500);
        }
    })

    if ($(".toc").length < 1) {
        $("#toc, #tocButton").hide();
        $(".switch-btn, .switch-area").show();
    }
</script>





    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <li id="bds_twi"><a href="#" class="bds_twi" data-cmd="twi" title="分享到推特"></a></li>
            <li id="bds_tsina"><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a></li>
            <li id="bds_sqq"><a href="#" class="bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a></li>
            <li id="bds_copy"><a href="#" class="bds_copy" data-cmd="copy" title="复制网址"></a></li>
            <li id="bds_mail"><a href="#" class="bds_mail" data-cmd="mail" title="通过邮件分享"></a></li>
            <li id="bds_weixin"><a href="#" class="bds_weixin" data-cmd="weixin" title="生成文章二维码"></a></li>
            <li id="bds_more"><a href="#" class="bds_more" data-cmd="more"></i></a></li>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"Android之内存管理初窥　| 赵天恩博客　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    




    <div class="scroll" id="post-nav-button">
        
            <a href="/2017/09/01/maven/mac_maven配置/" title="上一篇: mac上maven配置">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2016/04/23/android/android-checklist/" title="下一篇: Android开发过程中注意项(CheckList)">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2017/09/07/java/HashMap浅析（1.8.0_60版）/">HashMap浅析（1.8.0_60版）</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/java/rbac/RBAC/">RBAC</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/about/">关于我</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/实践Java虚拟机-JVM故障诊断与性能优化/">《实践Java虚拟机-JVM故障诊断与性能优化》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Linux私房菜-基础学习篇/">《Linux私房菜-基础学习篇》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/大数据之路-阿里巴巴大数据实践/">《大数据之路》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Java核心技术-卷1/">《Java核心技术-卷1》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Android系统源代码情景分析/">《Android系统源代码情景分析》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Hadoop权威指南/">《Hadoop权威指南》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Java并发编程-核心方法与框架/">《Java并发编程-核心方法与框架》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/Java核心技术-卷2/">《Java核心技术-卷2》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/深入解析Android5.0系统/">《深入解析Android5.0系统》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/高性能MySql/">《高性能MySql》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/重构-改善既有代码的设计/">《重构》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/架构即未来/">《架构即未来》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/深入实践SpringBoot/">《深入实践SpringBoot》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/第一行代码/">《第一行代码》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/阅读笔记/轻量级JavaEE企业应用实践/">《轻量级JavaEE企业应用实践》阅读笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/09/01/maven/mac_maven配置/">mac上maven配置</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/23/android/Android之内存管理初窥/">Android之内存管理初窥</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/23/android/android-checklist/">Android开发过程中注意项(CheckList)</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/17/android/android-common-technology/">Android无线开发的几种常用技术</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/10/hello-world/">Hello World</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/10/git/git/">Git使用笔记</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                &copy; 2017 赵天恩
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题">Yelee</a> by MOxFIVE
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" >本站到访数: 
                            <span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>, </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit">本页阅读量: 
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.1.22/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>




    <script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script src="//cdn.bootcss.com/mathjax/2.6.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>